#version 430 core

#define LOC_X 16
#define LOC_Y 16

#define GRID_SIZE_X 64
#define GRID_SIZE_Y 64
#define UNIT_OFFSET_X 1.f/(GRID_SIZE_X+1)
#define UNIT_OFFSET_Y 1.f/(GRID_SIZE_Y+1)
#define GRAVITY vec2(0.0f, -9.8f)

layout(local_size_x=LOC_X, local_size_y=LOC_Y) in;

layout(binding=0, rg32f) uniform image2D velocityImage;

void main(void)
{
	ivec2 gid = ivec2(gl_GlobalInvocationID.xy);
	if (gid.x <= GRID_SIZE_X && gid.y <= GRID_SIZE_Y)
	{
		//vec2 factor = vec2(greaterThan(gid, ivec2(1)) && lessThan(gid, ivec2(GRID_SIZE_X,GRID_SIZE_Y)-1));
		/*int offsetx = int(gid.x == 0) - int(gid.x == GRID_SIZE_X);
		int offsety = int(gid.y == 0) - int(gid.y == GRID_SIZE_Y);
		vec2 velocity = imageLoad(velocityImage, gid+ivec2(offsetx, offsety)).xy;
		velocity *= vec2(1.0 - 2.0*float(offsetx != 0), 1.0 - 2.0*float(offsety != 0));*/
		vec2 factor = vec2(greaterThan(gid, ivec2(0.0))) * vec2(lessThan(gid, ivec2(GRID_SIZE_X, GRID_SIZE_Y)));
		vec2 velocity = factor * imageLoad(velocityImage, gid).xy;
		imageStore(velocityImage, gid, vec4(velocity,0.0,1.0));
	}
}